<template>
	<view>
		<!-- 默认地址 -->
		<view class="address">
			<navigator hover-class="false" class="none" v-if="!address.unid" url="address">
				<i class="iconfont iconicon-test"></i>
				<text>新增收货地址</text>
			</navigator>
			<view class="default" v-else>
				<view class="default-left">
					<view class="default-info">{{address.user_name}}<text>{{address.phone}}</text></view>
					<view>{{address.address}}</view>
				</view>
				<navigator hover-class="false" class="default-right" url="address">
					<i class="iconfont iconfanhui"></i>
				</navigator>
			</view>
		</view>
		<!-- 商品信息 -->
		<view class="good">
			<view class="good-left">
				<image :src="detail.detail" mode="aspectFit"></image>
			</view>
			<view class="good-right">
				<view class="good-right-name">{{detail.goods_name}}</view>
				<view class="good-right-price"><span>{{detail.score}}</span>积分+￥{{detail.price}}</view>
			</view>
		</view>
		<!-- 支付信息 -->
		<view class="info">
			<view><label>商品数量</label><text>{{goodNum}}</text></view>
			<view><label>商品金额</label><text>￥{{detail.price*goodNum}}</text></view>
			<view class="info-freight"><label>运费</label><text>￥0</text></view>
			<view><label>积分抵扣</label><text>{{detail.score*goodNum}}</text></view>
		</view>
		<!-- 底部 -->
		<view class="bottom">
			<label>合计：￥{{detail.price*goodNum}}</label>
			<view :class="address.unid ? 'bottom-pay':'bottom-pay bottom-pay-none'" @click="pay">立即支付</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				market_id: uni.getStorageSync('market_id'), //所属上级ID
				address: {}, //默认收货地址
				goodId: '', //商品ID
				goodNum: 1, //商品购买数量
				detail: {}, //商品详情内容
			}
		},
		onLoad(e) {
			this.goodId = e.goodId;
			this.goodNum = e.num;
			this.getDeatil();
			this.getArea();
		},
		methods: {
			pay(){
				
				var data ={
					specs_id:this.specs_id_arr,
					address:this.address.address,
					usr_name:this.address.user_name,
					phone:this.address.phone,
					pay_type:"wxapp"
				}
				
				uni.navigateTo({
					url:'checkstand?total='+this.total+'&score='+this.score+'&data='+encodeURIComponent(JSON.stringify(data))
				})
				
			},
			// 获取商品详情
			getDeatil() {
				this.$sapi.apiPost('v1/' + this.market_id + '/mobile/goods/detail/' + this.goodId, {
					unid: this.goodId
				}).then(res => {
					if (res.data.code == 200 && res.data.data) {
						this.detail = res.data.data;
					} else {
						this.detail = {};
					}
				})
			},
			// 查询默认地址
			getArea() {
				this.$sapi.apiPost('v1/' + this.market_id + '/mobile/address/infos', {
					default: 1
				}).then(res => {
					if (res.data.code == 200 && res.data.data.length > 0) {
						this.address = res.data.data[0];
					} else {
						this.address = {};
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #F7F7F7;
	}

	.address,
	.good,
	.info {
		margin: 0upx 30upx 30upx;
		background-color: #FFFFFF;
		padding: 26upx 30upx;
		border-radius: 20upx;
	}

	/* 默认地址 */
	.address {
		margin-top: 48upx;

		.none {
			display: flex;
			align-items: center;
			justify-content: center;

			i {
				color: #333333;
				font-size: 50upx;
				line-height: 1;
				font-weight: bold;
				margin-right: 28upx;
			}

			text {
				color: #333333;
				font-size: 30upx;
			}
		}

		.default {
			display: flex;
			align-items: center;
			justify-content: space-between;

			.default-left {
				width: 92%;

				.default-info {
					color: #333333;
					font-size: 30upx;
					display: flex;
					align-items: center;

					text {
						color: #A8A8A8;
						margin-left: 10upx;
					}
				}
			}

			.default-right {
				color: #A8A8A8;
				font-size: 20upx;
			}
		}
	}

	/* 商品信息 */
	.good {
		display: flex;
		align-items: center;

		.good-left {
			height: 88upx;
			width: 96upx;
			padding: 20upx 16upx;
			border: 2upx solid #A8A8A8;
			border-radius: 8upx;
			margin-right: 52upx;

			image {
				width: 100%;
				height: 100%;
			}
		}

		.good-right {
			width: calc(100% - 150upx);

			.good-right-name {
				color: #2D5363;
				font-size: 34upx;
				white-space: nowrap;
				overflow: hidden;
				text-overflow: ellipsis;
			}

			.good-right-price {
				color: #FF0000;
				font-size: 26upx;
				font-weight: 300;

				span {
					font-size: 50upx;
					font-weight: 500;
					margin-right: 8upx;
				}
			}
		}
	}

	/* 支付信息 */
	.info {
		view {
			display: flex;
			align-items: center;
			justify-content: space-between;
			margin-bottom: 20upx;

			label {
				color: #333333;
				font-size: 34upx;
			}

			text {
				color: #FF0000;
			}
		}

		.info-freight {
			text {
				color: #333333;
			}
		}
	}

	/* 底部 */
	.bottom {
		position: fixed;
		left: 0;
		bottom: 0;
		width: 100%;
		height: 100upx;
		background-color: #FFFFFF;
		box-shadow: 0px 0px 0px rgba(0, 0, 0, 0.16);
		color: #333333;
		font-size: 34upx;
		display: flex;
		align-items: center;
		justify-content: space-between;
		label{
			margin-left: 30upx;
		}

		.bottom-pay {
			color: #FFFFFF;
			padding: 0 50upx;
			background-color: #FFB800;
			line-height: 100upx;
			font-size: 34upx;
		}
		.bottom-pay-none{
			background-color: #CCCCCC;
		}
	}
</style>
